<?php
/*
 * Theme TNT => 评论模块
*/
defined('ABSPATH') or die('This file can not be loaded directly.');
global $comment_ids; $comment_ids = array();
foreach ( $comments as $comment ) {
	if (get_comment_type() == "comment") {
		$comment_ids[get_comment_id()] = ++$comment_i;
	}
} 

if ( have_comments() ) { 
	$my_email = get_bloginfo ( 'admin_email' );
	$str = "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND comment_approved = '1' AND comment_type = '' AND comment_author_email";
	$count_t = $post->comment_count;
	$count_v = $wpdb->get_var("$str != '$my_email'");
	$count_h = $wpdb->get_var("$str = '$my_email'");
?>
<section id="postcomments">
	<h3 class="base-tit" id="comments">
		评论&nbsp;.&nbsp;.&nbsp;.&nbsp;.&nbsp;.&nbsp;.&nbsp;.
		<span class="reply"><?php if($count_h>0){ echo '博主回复<strong>'.$count_h.'</strong>条'; } ?></span>
	</h3>
	<ol class="commentlist">
		<?php wp_list_comments('type=comment&callback=dtheme_comment_list') ?>
	</ol>
	<p class="pagenav">
		<?php paginate_comments_links('prev_next=0');?>
	</p>
</section>
<?php 
} 

if ( comments_open() ) { 
?>
<section id="respond" class="no_webshot">
	<h3 class="base-tit">
		<?php comment_form_title('我来说说', '评论回复 %s'); ?>
	</h3>
	<?php if ( get_option('comment_registration') && !is_user_logged_in() ) { ?>
	<h3 class="queryinfo">
		<?php printf('发表评论您必须先<a href="%s">登录</a>！', wp_login_url( get_permalink() ) );?>
	</h3>
	<?php } else { ?>
	<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    	<div class="author" id="author">
		
		<div class="user-logged">
		<?php if ( $user_ID ) : ?>

			<div class="real-avatar">
			<?php echo get_avatar( $user_ID, 36 ); ?>
        	</div>
			<?php printf('欢迎 %s！！', '<a href="'.get_option('siteurl').'/wp-admin/profile.php">'.$user_identity.'</a>'); ?> 
			<a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php echo '换个马甲 &raquo;'; ?>"><?php echo '退出 &raquo;'; ?></a>	

		<?php elseif ( '' != $comment_author ): ?>
			
			<div class="real-avatar">
			<?php echo get_avatar( $comment_author_email, 36 ); ?>
	        </div>
			<?php printf(__('欢迎留言 <strong>%s</strong>'), $comment_author); ?>
			<a href="javascript:toggleCommentAuthorInfo();" id="toggle-comment-author-info">[ 更改 ]</a>
	
			<script type="text/javascript" charset="utf-8">
		 	window.onload = function(){
			 	var cominfor = document.getElementById("comment-author-info")
			 	cominfor.style.display = "none";
			}
			var changeMsg = "[ 更改 ]";var closeMsg = "[ 隐藏 ]";
			function toggleCommentAuthorInfo() {
				jQuery('#comment-author-info').slideToggle('slow', function(){
					if ( jQuery('#comment-author-info').css('display') == 'none' ) {
						jQuery('#toggle-comment-author-info').text(changeMsg);
						} 
					else {
						jQuery('#toggle-comment-author-info').text(closeMsg);
					};
				});
			}
		</script>	
		<?php endif; ?>
		</div>
		<?php if ( ! $user_ID ): ?>
		<div id="comment-author-info">
			<p><label for="author">昵称</label><input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="14" tabindex="1" /><small>（必须）</small></p>
			<p><label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="25" tabindex="2" /><small>（必须，保密）</small></p>
			<p><label for="url">网站</label><input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="36" tabindex="3" /></p>
		</div>
		 <?php endif; ?>
		<div class="post-area">
			<div id="smiley" class="toggle"><?php dtheme_smilies(); ?></div>
			<div class="post-area-txt"><?php echo stripslashes(get_option('d_commentarea')); ?></div>
			<textarea name="comment" id="comment" cols="100%" rows="7" tabindex="4" onkeydown="if(event.ctrlKey&amp;&amp;event.keyCode==13){document.getElementById('submit').click();return false};"></textarea>
		</div>
		<div class="subcon">
			<div class="choose"><?php comment_id_fields(); do_action('comment_form', $post->ID); ?></div>
            <input class="btn confirm" type="submit" name="submit" id="submit" tabindex="5" value="好了,提交评论" />
			<input class="btn confirm" type="reset" value="重写" id="reset" name="reset">
		</div>
       
	  	<div class="sns"><?php wp_connect();?></div>
	</form>
	
	<?php } ?>
</section>
<?php } else { ?>
	<h3 class="queryinfo" style="margin:0 6px 15px">访客评论被关闭！</h3>
<?php } ?>